package com.example.cartserver.controller;


import com.example.cartserver.entities.Cart;
import com.example.cartserver.service.CartService;
import com.example.server_engineer.controller.AbstractTypedController;
import com.example.server_engineer.controller.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("cart")
@Tag(name = "购物车控制器")
public class CartController extends AbstractTypedController<Cart,Integer> {

    @Resource
    CartService csvc;
    CartController(CartService cartService){
        this.svcContext = cartService;
    }

    @Operation(summary = "查看用户的购物车")
    @GetMapping("/query/byuser")
    public List<Cart> queryCartByUserId(String id){
        return csvc.queryCartByUserId(id);
    }

    @Operation(summary = "查看用户在某个商家的购物车")
    @GetMapping("/query/by/uandb")
    public List<Cart> queryCartByBusinessIDAndUserId(Integer businessid,String userid){
        return csvc.queryByBusinessIdAndUserId(businessid,userid);
    }

    @Operation(summary = "查看购物车详细信息")
    @GetMapping("/query/cart_detail")
    public R queryDetaile(Integer cartid){
        return csvc.queryCartInfo(cartid);
    }

    @Operation(summary = "查看当前用户在某个商家的某个食物的数量")
    @PostMapping("/query/foodnum")
    public Cart queryFoodnum(@Parameter String userid, @Parameter int businessid, int foodid){
        System.out.println("businessid"+businessid);
        System.out.println("userid"+userid);
        System.out.println("foodid"+foodid);
        return csvc.queryFoodnum(userid,businessid,foodid);
    }
}
